home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 9 / Night Owl CD-ROM (NOPV9) (Night Owl Publisher) (1993).ISO / 006a / cshot101.zip / CS-HOT.C < prev    next >
C/C++ Source or Header  |  1993-03-02  |  7KB  |  200 lines

  1. /*  CS-HOT version 1.01        Copyright (C) 1993 by Jim Robeson
  2.  *                                                      3/02/93
  3.  *  Function:
  4.  *    Read the output of PCBCS143 (arg-1),
  5.  *      and strip it down to a "hotfile" report (arg-2),
  6.  *      according to the FORMat requested (arg-3).
  7.  *         "FORM" must be 1 or 2 or 3
  8.  *                1 = output only "files downloaded" section
  9.  *                2 = also include the "1st page stats" section
  10.  *                3 = also include the "multi-node" section,
  11.  *                    (if it exists).
  12.  *
  13.  *  Other uses:
  14.  *    None.
  15.  *
  16.  *  Execution:
  17.  *    Run from command line or .BAT:
  18.  *      CS-HOT drv:\path\in-file-name drv:\path\out-file-name FORM
  19.  *    If run without arguments, a bit of help appears.
  20.  *
  21.  *  Compiled with:
  22.  *    Borland's Turbo C 2.0.
  23.  *    tcc cs-hot
  24.  *
  25.  *  Disclaimer:
  26.  *    This program is contributed to the Public Domain.  It can be
  27.  *    freely used, modified and/or distributed by anyone. The only
  28.  *    thing I ask is that you remember that I am not responsible
  29.  *    for anything that might go wrong through the use of this
  30.  *    program.  I have tested the program enough for my own use.
  31.  *    I also realize that bugs can appear in most every program.
  32.  *    Therefore, YOU USE THIS PROGRAM AT YOUR OWN RISK.
  33.  *
  34.  *  To-do:
  35.  *
  36.  *  Enjoy,
  37.  *  Jim Robeson
  38.  *  The Cricket BBS, Pacific Grove CA,  408-373-3773
  39.  */
  40.  
  41. #include "stdio.h"         /* Standard I/O definitions */
  42. #include "string.h"
  43.  
  44. #define TRUE 1
  45. #define FALSE 0
  46.  
  47. void showhelp ( );         /* prototype */
  48.  
  49.   FILE *infile;            /* the IN file */
  50.   FILE *outfile;           /* the OUT file */
  51.   char inbuf[BUFSIZ];      /* line buffer for reading from file */
  52.                            /* BUFSIZ = 512 in stdio.h */
  53.   int ipt,opt,i;           /* index pointers */
  54.   int phase;
  55.   int linecnt;
  56.  
  57. char *isitTTL = "            PCB Caller Statistics Version 1.43";
  58. char *isitMLT = "                              Multinode Statistics";
  59. char *isitHOT = "                         Files downloaded --- by Count";
  60.  
  61. /* ========================================= */
  62. /* ===  MAIN                             === */
  63. /* ========================================= */
  64. main(int argc, char *argv[])       /* main reads command args  */
  65. {
  66.   char *progname;
  67.   char *filein;
  68.   char *fileout;
  69.   char *form;
  70.  
  71. /*  Display a little how-to "help" if arguments are null or improper  */
  72.  
  73.   if (argc != 4)           /*  should be 3 args + prognam */
  74.      { if (argc != 1)
  75.          printf("\nERROR: needs 3 arguments\n");
  76.        showhelp();
  77.        exit (1); }               /* exit with errorlevel=1 */
  78.  
  79.   progname = argv[0];
  80.   filein   = argv[1];
  81.   fileout  = argv[2];
  82.   form     = argv[3];
  83.  
  84.   if (form[0] == '1' || form[0] == '2' || form[0] == '3') ;
  85.      else
  86.      { printf("\nERROR: FORM MUST = 1, 2 OR 3\n");
  87.        showhelp();
  88.        exit (1); }               /* exit with errorlevel=1 */
  89.  
  90.   printf("\nCS-HOT IS RUNNING.  Input = %s, Output = %s, FORM = %s.\n",filein,fileout,form);
  91.  
  92.   infile = fopen(filein,"r");          /* open the input file */
  93.   if (infile == NULL)
  94.     {
  95.     fprintf(stderr,"\n\007%s can't open the INPUT file: %s.\n",progname,filein);
  96.     exit (1);
  97.     }
  98.  
  99.   outfile = fopen(fileout,"w");          /* open the output file */
  100.   if (outfile == NULL)
  101.     {
  102.     fprintf(stderr,"\n\007%s can't open the OUTPUT file: %s.\n",progname,fileout);
  103.     exit (1);
  104.     }
  105.  
  106.   phase = 1;
  107.   linecnt = 0;
  108.  /* ========================  copy the file ========================= */
  109.   while ( fgets(inbuf,BUFSIZ,infile) != NULL )  /* TOP-OF-LOOP */
  110.     {
  111.  
  112.     switch (phase)
  113.  
  114.       { case 1 :       /* copy the first 3 lines as-is */
  115.           fprintf(outfile,"%s",inbuf);
  116.           linecnt++;
  117.           if (linecnt == 4) phase = 2;
  118.           break;
  119.  
  120.         case 2 :       /* copy 1st STAT PAGE until next title */
  121.           if ( strncmp(inbuf,isitTTL,strlen(isitTTL)) == 0 )    /* test for Vern's page title */
  122.             { fprintf(outfile,"\n");  /* found it, stuff a blank line */
  123.               phase = 3;
  124.               break;
  125.             }
  126.           if (form[0] == '2' || form[0] == '3')
  127.             fprintf(outfile,"%s",inbuf);
  128.           break;
  129.  
  130.         case 3 :       /* now, skip to the multi-node section */
  131.           if ( strncmp(inbuf,isitHOT,strlen(isitHOT)) == 0 )    /* test for mulit-node line */
  132.             { fprintf(outfile,"%s",inbuf);    /* write it out */
  133.               phase = 6;
  134.               break;
  135.             }
  136.           if ( strncmp(inbuf,isitMLT,strlen(isitMLT)) == 0 )    /* test for mulit-node line */
  137.             { if (form[0] == '3')
  138.                 fprintf(outfile,"%s",inbuf);    /* write it out */
  139.               phase = 4;
  140.               break;
  141.             }
  142.           break;
  143.  
  144.         case 4 :       /* copy MULTI-NODE report until next title */
  145.           if ( strncmp(inbuf,isitTTL,strlen(isitTTL)) == 0 )    /* test for Vern's page title */
  146.             { fprintf(outfile,"\n");  /* found it, stuff a blank line */
  147.               phase = 5;
  148.               break;
  149.             }
  150.           if (form[0] == '3')
  151.             fprintf(outfile,"%s",inbuf);
  152.           break;
  153.  
  154.         case 5 :       /* now, skip to the hot-file section */
  155.           if ( strncmp(inbuf,isitHOT,strlen(isitHOT)) == 0 )    /* test for mulit-node line */
  156.             { fprintf(outfile,"%s",inbuf);    /* write it out */
  157.               phase = 6;
  158.               break;
  159.             }
  160.           break;
  161.  
  162.         case 6 :       /* copy the HOTFILES to end, except page titles */
  163.           if ( strncmp(inbuf,isitTTL,strlen(isitTTL)) == 0 )    /* test for Vern's page title */
  164.              break;
  165.           fprintf(outfile,"%s",inbuf);
  166.           break;
  167.  
  168.         default:
  169.           fprintf(stderr,"\nYO, HOW DID I GET HERE, OH MASTER?\n");
  170.           exit (1);
  171.       } /* end of switch */
  172.  
  173.     } /* end of while at TOP-OF-LOOP */
  174.  
  175.   /* === Since we dropped through,  ============== */
  176.   /* === implies end of file found. ============== */
  177.  
  178.   fclose(infile);
  179.   fclose(outfile);
  180.  
  181.   printf("CS-HOT IS FINISHED.\n");
  182.   exit (0);      /* job done, get out, errorvalue = 0 */
  183.  
  184. }  /* ------------- end of main ------------------------------- */
  185.  
  186. /* ========================================= */
  187. /* ===  SHOWHELP                         === */
  188. /* ========================================= */
  189. void showhelp ()
  190. {
  191.   printf("\nCS-HOT v1.01:\n");
  192.   printf("    Strip PCBCS reports into a smaller form.\n");
  193.   printf("    by Jim Robeson,  3-02-93\n\n");
  194.   printf("USAGE:\n");
  195.   printf("    CS-HOT drv:\path\in-file-name drv:\path\out-file-name FORM\n");
  196.   return;
  197. }  /* ------------- end of showhelp --------------------------- */
  198.  
  199. /*------------- End of CS-HOT.C ------------------------------------*/
  200.